<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>SpringBoot EasyUrlTask</title>
    <#include "/header.html">

</head>
<body>

<el-container>

    <el-container>
        <el-main>
            <#--内容展示-->
            <div id="app">
            <el-form ref="form" :model="formData" label-width="120px">
                <el-form-item label="请求ID">
                    <el-input v-model="formData.requestId" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="请求方式">
                    <el-radio-group v-model="formData.method" placeholder="请求方式">
                        <el-radio label="POST" value="POST" ></el-radio>
                        <el-radio label="GET" value="GET"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="启用状态">
                    <el-radio-group v-model="formData.status" placeholder="启用状态">
                        <el-radio  :label="1" >启用</el-radio >
                        <el-radio  :label="0" >暂停</el-radio >
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="Token URL">
                    <el-input type="textarea" v-model="formData.tokenUrl"></el-input>
                </el-form-item>
                <el-form-item label="请求参数JSON">
                    <el-input type="textarea" v-model="formData.param"></el-input>
                </el-form-item>
                <el-form-item label="请求参数类型">
                    <el-radio-group v-model="formData.paramType" placeholder="请求参数类型">
                        <el-radio  label="FORM" value="FORM"></el-radio >
                        <el-radio  label="JSON" value="JSON" ></el-radio >
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="获取TOKEN表达式">
                    <el-input type="textarea" v-model="formData.tokenExpression"></el-input>
                </el-form-item>
                <el-form-item label="追加Token参数">
                    <el-input type="textarea" v-model="formData.appendName"></el-input>
                </el-form-item>
                <el-form-item label="追加Token方式">
                    <el-radio-group  v-model="formData.appendType" placeholder="追加方式">
                        <el-radio  label="URL" value="URL" ></el-radio >
                        <el-radio  label="FORM" value="FORM"></el-radio >
                    </el-radio-group >
                </el-form-item>
                <el-form-item>
                    <el-button type="success" @click="onTest">测试</el-button>
                    <el-button type="primary" @click="onSubmit">保存</el-button>
                    <el-button @click="close">返回</el-button>
                </el-form-item>

            </el-form>
            </div>
        </el-main>
    </el-container>
</el-container>


</body>
<style>
    .el-header {
        background-color: #B3C0D1;
        color: #333;
        line-height: 60px;
    }

    .el-aside {
        color: #333;
    }
</style>

<script>
    const Main = {
        data() {
            return {
                formData: {
                    "requestId": "${requestId!!}",
                    "tokenUrl": "",
                    "method": "POST",
                    "param": "",
                    "paramType": "JSON",
                    "appendType": "URL",
                    "appendName": "",
                    "tokenExpression": "",
                    "status": "1" ,
                }
            }
        },
        created: function () {
            // 组件创建完后获取数据，
            // 此时 data 已经被 observed 了
            this.fetchData();
        },
        methods: {
            fetchData: function () {
                let that = this;
                $.ajax({
                    type: "POST",
                    url: baseURL + "urlPlus/token/info",
                    contentType: "application/json",
                    data: JSON.stringify(this.formData),
                    success: function(r){
                        console.log(r)
                        if(r.code === 0){
                            that.formData = r.data;
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            },
            onSubmit: function () {
                //发送post请求
                $.ajax({
                    type: "POST",
                    url: baseURL + "urlPlus/token/save",
                    contentType: "application/json",
                    data: JSON.stringify(this.formData),
                    success: function(r){
                        if(r.code === 0){
                            alert('操作成功');
                        }else{
                            error(r.msg);
                        }
                    }
                });
            },
            onTest: function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "urlPlus/token/test",
                    contentType: "application/json",
                    data: JSON.stringify(this.formData),
                    success: function(r){
                        if(r.code === 0){
                            alert('测试成功,TOKEN为:'+r.msg);
                        }else{
                            error(r.msg);
                        }
                    }
                });
            },
            onCLose: function () {
                //关闭窗口方法
                const userAgent = navigator.userAgent;
                if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
                    window.location.href="about:blank";
                    window.close();
                } else {
                    window.opener = null;
                    window.open("", "_self");
                    window.close();
                }
            }
        }
    };
    const Ctor = Vue.extend(Main);
    new Ctor().$mount('#app')
</script>
</html>